home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / AIncludes / fenv.a < prev    next >
Encoding:
Text File  |  1997-08-12  |  11.6 KB  |  316 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        fenv.a
  3. ;
  4. ;    Contains:    Floating-Point environment for PowerPC and 68K
  5. ;
  6. ;    Version:    Technology:    MathLib v2
  7. ;                Release:    Universal Interfaces 3.0.1
  8. ;
  9. ;    Copyright:    © 1987-1997 by Apple Computer, Inc., all rights reserved.
  10. ;
  11. ;    Bugs?:        Please include the the file and version information (from above) with
  12. ;                the problem description.  Developers belonging to one of the Apple
  13. ;                developer programs can submit bug reports to:
  14. ;
  15. ;                    devsupport@apple.com
  16. ;
  17. ;
  18.     IF &TYPE('__FENV__') = 'UNDEFINED' THEN
  19. __FENV__ SET 1
  20.  
  21.     IF &TYPE('__CONDITIONALMACROS__') = 'UNDEFINED' THEN
  22.     include 'ConditionalMacros.a'
  23.     ENDIF
  24.  
  25. ;        A collection of functions designed to provide access to the floating
  26. ;        point environment for numerical programming. It is modeled after
  27. ;        the floating-point requirements in C9X.
  28. ;        
  29. ;        The file <fenv.h> declares many functions in support of numerical
  30. ;        programming.  It provides a set of environmental controls similar to
  31. ;        the ones found in <SANE.h>.  Programs that test flags or run under
  32. ;        non-default modes must do so under the effect of an enabling
  33. ;        "fenv_access" pragma.
  34. ;
  35.  
  36.  
  37.     IF TARGET_CPU_PPC THEN
  38. ;     The typedef fenv_t is a type for representing the entire floating-point
  39. ;      environment in a single object.                                         
  40. ; typedef long                             fenv_t
  41.  
  42. ;     The typedef fexcept_t is a type for representing the floating-point
  43. ;      exception flag state collectively.                                      
  44. ; typedef long                             fexcept_t
  45.  
  46. ;     Definitions of floating-point exception macros                          
  47.  
  48. FE_INEXACT                        EQU        $02000000
  49. FE_DIVBYZERO                    EQU        $04000000
  50. FE_UNDERFLOW                    EQU        $08000000
  51. FE_OVERFLOW                        EQU        $10000000
  52. FE_INVALID                        EQU        $20000000
  53. ;     Definitions of rounding direction macros                                
  54.  
  55. FE_TONEAREST                    EQU        $00000000
  56. FE_TOWARDZERO                    EQU        $00000001
  57. FE_UPWARD                        EQU        $00000002
  58. FE_DOWNWARD                        EQU        $00000003
  59.     ENDIF    ; TARGET_CPU_PPC
  60.     IF TARGET_CPU_68K THEN
  61.     IF TARGET_RT_MAC_68881 THEN
  62. ; typedef long                             fexcept_t
  63.  
  64. fenv_t                    RECORD 0
  65. FPCR                     ds.l    1                ; offset: $0 (0)
  66. FPSR                     ds.l    1                ; offset: $4 (4)
  67. sizeof                     EQU *                    ; size:   $8 (8)
  68.                         ENDR
  69.  
  70. FE_INEXACT                        EQU        $00000008            ; ((long)(8))   
  71. FE_DIVBYZERO                    EQU        $00000010            ; ((long)(16))  
  72. FE_UNDERFLOW                    EQU        $00000020            ; ((long)(32))  
  73. FE_OVERFLOW                        EQU        $00000040            ; ((long)(64))  
  74. FE_INVALID                        EQU        $00000080            ; ((long)(128)) 
  75.     ELSE
  76. ; typedef short                         fexcept_t
  77.  
  78. ; typedef short                         fenv_t
  79.  
  80.  
  81. FE_INVALID                        EQU        $0001                ; ((short)(1))  
  82. FE_UNDERFLOW                    EQU        $0002                ; ((short)(2))  
  83. FE_OVERFLOW                        EQU        $0004                ; ((short)(4))  
  84. FE_DIVBYZERO                    EQU        $0008                ; ((short)(8))  
  85. FE_INEXACT                        EQU        $0010                ; ((short)(16)) 
  86.     ENDIF    ; TARGET_RT_MAC_68881
  87.  
  88. FE_TONEAREST                    EQU        $0000                ; ((short)(0))  
  89. FE_UPWARD                        EQU        $0001                ; ((short)(1))  
  90. FE_DOWNWARD                        EQU        $0002                ; ((short)(2))  
  91. FE_TOWARDZERO                    EQU        $0003                ; ((short)(3))  
  92. ;     Definitions of rounding precision macros  (68K only)                    
  93.  
  94. FE_LDBLPREC                        EQU        $0000                ; ((short)(0))  
  95. FE_DBLPREC                        EQU        $0001                ; ((short)(1))  
  96. FE_FLTPREC                        EQU        $0002                ; ((short)(2))  
  97.     ENDIF    ; TARGET_CPU_68K
  98. ;     The bitwise OR of all exception macros                                  
  99. ; *******************************************************************************
  100. ;*     The following functions provide access to the exception flags.  The      *
  101. ;*     "int" input argument can be constructed by bitwise ORs of the exception  *
  102. ;*     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  103. ;******************************************************************************
  104.  
  105. ; *******************************************************************************
  106. ;*     The function "feclearexcept" clears the supported exceptions represented *
  107. ;*     by its argument.                                                         *
  108. ;******************************************************************************
  109.  
  110. ;
  111. ; extern void feclearexcept(int excepts)
  112. ;
  113.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  114.         IMPORT_CFM_FUNCTION feclearexcept
  115.     ENDIF
  116.  
  117.  
  118.  
  119. ; *******************************************************************************
  120. ;*    The function "fegetexcept" stores a representation of the exception       *
  121. ;*     flags indicated by the argument "excepts" through the pointer argument   *
  122. ;*     "flagp".                                                                 *
  123. ;******************************************************************************
  124.  
  125. ;
  126. ; extern void fegetexcept(fexcept_t *flagp, int excepts)
  127. ;
  128.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  129.         IMPORT_CFM_FUNCTION fegetexcept
  130.     ENDIF
  131.  
  132.  
  133.  
  134. ; *******************************************************************************
  135. ;*     The function "feraiseexcept" raises the supported exceptions             *
  136. ;*     represented by its argument.                                             *
  137. ;******************************************************************************
  138.  
  139. ;
  140. ; extern void feraiseexcept(int excepts)
  141. ;
  142.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  143.         IMPORT_CFM_FUNCTION feraiseexcept
  144.     ENDIF
  145.  
  146.  
  147.  
  148. ; *******************************************************************************
  149. ;*     The function "fesetexcept" sets or clears the exception flags indicated  *
  150. ;*     by the int argument "excepts" according to the representation in the     *
  151. ;*     object pointed to by the pointer argument "flagp".  The value of         *
  152. ;*     "*flagp" must have been set by a previous call to "fegetexcept".         *
  153. ;*     This function does not raise exceptions; it just sets the state of       *
  154. ;*     the flags.                                                               *
  155. ;******************************************************************************
  156.  
  157. ;
  158. ; extern void fesetexcept(const fexcept_t *flagp, int excepts)
  159. ;
  160.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  161.         IMPORT_CFM_FUNCTION fesetexcept
  162.     ENDIF
  163.  
  164.  
  165.  
  166. ; *******************************************************************************
  167. ;*     The function "fetestexcept" determines which of the specified subset of  *
  168. ;*     the exception flags are currently set.  The argument "excepts" specifies *
  169. ;*     the exception flags to be queried as a bitwise OR of the exception       *
  170. ;*     macros.  This function returns the bitwise OR of the exception macros    *
  171. ;*     corresponding to the currently set exceptions included in "excepts".     *
  172. ;******************************************************************************
  173.  
  174. ;
  175. ; extern int fetestexcept(int excepts)
  176. ;
  177.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  178.         IMPORT_CFM_FUNCTION fetestexcept
  179.     ENDIF
  180.  
  181.  
  182.  
  183. ; *******************************************************************************
  184. ;*     The following functions provide control of rounding direction modes.     *
  185. ;******************************************************************************
  186.  
  187. ; *******************************************************************************
  188. ;*     The function "fegetround" returns the value of the rounding direction    *
  189. ;*     macro which represents the current rounding direction.                   *
  190. ;******************************************************************************
  191.  
  192. ;
  193. ; extern int fegetround(void )
  194. ;
  195.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  196.         IMPORT_CFM_FUNCTION fegetround
  197.     ENDIF
  198.  
  199.  
  200.  
  201. ; *******************************************************************************
  202. ;*     The function "fesetround" establishes the rounding direction represented *
  203. ;*     by its argument.  It returns nonzero if and only if the argument matches *
  204. ;*     a rounding direction macro.  If not, the rounding direction is not       *
  205. ;*     changed.                                                                 *
  206. ;******************************************************************************
  207.  
  208. ;
  209. ; extern int fesetround(int round)
  210. ;
  211.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  212.         IMPORT_CFM_FUNCTION fesetround
  213.     ENDIF
  214.  
  215.  
  216.  
  217. ; *******************************************************************************
  218. ;*    The following functions manage the floating-point environment, exception  *
  219. ;*    flags and dynamic modes, as one entity.                                   *
  220. ;******************************************************************************
  221.  
  222. ; *******************************************************************************
  223. ;*     The function "fegetenv" stores the current floating-point environment    *
  224. ;*     in the object pointed to by its pointer argument "envp".                 *
  225. ;******************************************************************************
  226.  
  227. ;
  228. ; extern void fegetenv(fenv_t *envp)
  229. ;
  230.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  231.         IMPORT_CFM_FUNCTION fegetenv
  232.     ENDIF
  233.  
  234.  
  235.  
  236. ; *******************************************************************************
  237. ;*     The function "feholdexcept" saves the current environment in the object  *
  238. ;*     pointed to by its pointer argument "envp", clears the exception flags,   *
  239. ;*     and clears floating-point exception enables.  This function supersedes   *
  240. ;*     the SANE function "procentry", but it does not change the current        *
  241. ;*     rounding direction mode.                                                 *
  242. ;******************************************************************************
  243.  
  244. ;
  245. ; extern int feholdexcept(fenv_t *envp)
  246. ;
  247.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  248.         IMPORT_CFM_FUNCTION feholdexcept
  249.     ENDIF
  250.  
  251.  
  252.  
  253. ; *******************************************************************************
  254. ;*     The function "fesetenv" installs the floating-point environment          *
  255. ;*     environment represented by the object pointed to by its argument         *
  256. ;*     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  257. ;*     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  258. ;*     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  259. ;******************************************************************************
  260.  
  261. ;
  262. ; extern void fesetenv(const fenv_t *envp)
  263. ;
  264.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  265.         IMPORT_CFM_FUNCTION fesetenv
  266.     ENDIF
  267.  
  268.  
  269.  
  270. ; *******************************************************************************
  271. ;*     The function "feupdateenv" saves the current exceptions into its         *
  272. ;*     automatic storage, installs the environment represented through its      *
  273. ;*     pointer argument "envp", and then re-raises the saved exceptions.        *
  274. ;*     This function, which supersedes the SANE function "procexit", can be     *
  275. ;*     used in conjunction with "feholdexcept" to write routines which hide     *
  276. ;*     spurious exceptions from their callers.                                  *
  277. ;******************************************************************************
  278.  
  279. ;
  280. ; extern void feupdateenv(const fenv_t *envp)
  281. ;
  282.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  283.         IMPORT_CFM_FUNCTION feupdateenv
  284.     ENDIF
  285.  
  286.  
  287.  
  288.     IF TARGET_CPU_68K THEN
  289. ; *******************************************************************************
  290. ;*     The following functions provide control of rounding precision.           *
  291. ;*     Because the PowerPC does not provide this capability, these functions    *  
  292. ;*     are available only for the 68K Macintosh.  Rounding precision values     *
  293. ;*     are defined by the rounding precision macros.  These functions are       *
  294. ;*     equivalent to the SANE functions getprecision and setprecision.          *
  295. ;******************************************************************************
  296.  
  297. ;
  298. ; extern int fegetprec(void )
  299. ;
  300.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  301.         IMPORT_CFM_FUNCTION fegetprec
  302.     ENDIF
  303.  
  304. ;
  305. ; extern int fesetprec(int precision)
  306. ;
  307.     IF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  308.         IMPORT_CFM_FUNCTION fesetprec
  309.     ENDIF
  310.  
  311.     ENDIF    ; TARGET_CPU_68K
  312.  
  313.     ENDIF ; __FENV__ 
  314.  
  315.